package com.uniview.controller;

import com.uniview.dto.RespDTO;
import com.uniview.orm.model.AuthClientDetails;
import com.uniview.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author lux
 * @date: 2019/11/13
 * @desc: 用户控制器
 */
@RestController
public class UserController {
    @Autowired
    UserService userService;

    /**
     * @desc 用户注册
     * @param userName 用户名
     * @param password 用户密码
     * @return map
     */
    @RequestMapping("/register")
    public void register(@RequestParam("userName") String userName,
                            @RequestParam("password") String password){
        userService.register(userName,password);
    }

    @RequestMapping("/login")
    public RespDTO<Map<String,Object>> login(@RequestParam("userName") String userName,
                      @RequestParam("password") String password){
        Map<String,Object> userMap =  userService.login(userName,password);
        return RespDTO.onSuc(userMap);
    }

    /**
     * @desc oauth客户端注册
     * @param clientName
     * @param redirectUri
     * @param grantTypes 逗号拼接的字符串
     */
    @RequestMapping("/clientRegister")
    public RespDTO<AuthClientDetails> clientRegister(@RequestParam("clientName") String clientName,
                                                     @RequestParam("redirectUri") String redirectUri,
                                                     @RequestParam("grantTypes") String grantTypes,
                                                     @RequestParam("scopes") String scopes){
        AuthClientDetails authClientDetails = userService.register(clientName,redirectUri,grantTypes,scopes);
        return RespDTO.onSuc(authClientDetails);
    }




}
